#!/usr/bin/env python
# vim:fileencoding=utf-8
if __name__=='__main__':
    import sys
    if len(sys.argv)<2:
        exit()

    #日志初始化
    #信息等级：
    #级别        对应的值
    #CRITICAL    50
    #ERROR       40
    #WARNING     30
    #INFO 	     20
    #DEBUG 	     10
    #NOTSET      0
    import os,logging 
    script_path=sys.path[0]+os.path.sep+sys.argv[1].replace('.',os.path.sep)
    log_path=os.path.dirname(script_path)+os.path.sep+'log'+os.path.sep+ os.path.basename(script_path)+'.log'    # log路径
    strFormat = '%(asctime)s|%(filename)s|line:%(lineno)d|%(levelname)s|%(message)s'
    strDatefmt = '%Y-%m-%d %H:%M:%S'

    logging.basicConfig(filename=log_path,level=logging.INFO,format=strFormat,datefmt=strDatefmt)

    # 定义StreamHandler,将Log信息输出到屏幕
    console = logging.StreamHandler()
    console.setLevel(logging.INFO)
    formatter = logging.Formatter(strFormat,strDatefmt)
    console.setFormatter(formatter)
    logging.getLogger('').addHandler(console)

    cmd_line=' '.join(sys.argv)
    logging.log(logging.INFO,cmd_line+'   ...start')

    #运行 目标脚本
    __import__(sys.argv[1])

    #运行结束日志
    logging.log(logging.INFO,cmd_line+'   ...end')

